package net.wanho.shop.controller;


import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.wanho.shop.po.GoodsPics;
import net.wanho.shop.service.GoodsPicsService;
import net.wanho.shop.vo.AjaxResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;


/**
 * <p>
 * 商品图片表 前端控制器
 * </p>
 *
 * @author 猛虎王
 * @since 2024-12-24
 */
@Api(tags = "商品图片表接口")
@RestController
@RequestMapping("/goods-pics")
@RequiredArgsConstructor
public class GoodsPicsController {

    private final GoodsPicsService goodsPicsService;

    @ApiOperation("商品图片表分页查询")
    @GetMapping("/list")
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pagenum, @ApiParam("页大小") @RequestParam(defaultValue = "5") int pagesize, @ApiParam("查询条件") GoodsPics goodsPics) {
        PageInfo<GoodsPics> pageInfo = goodsPicsService.findPage(pagenum, pagesize, goodsPics);
        return AjaxResult.success(pageInfo);
    }

    @ApiOperation("根据主键查询商品图片表")
    @GetMapping("/{picsId}")
    public AjaxResult findById(@PathVariable Serializable picsId) {
        return AjaxResult.success(goodsPicsService.findById(picsId));
    }

    @ApiOperation("新增商品图片表")
    @PostMapping
    public AjaxResult add(@RequestBody GoodsPics goodsPics) {
        goodsPicsService.add(goodsPics);
        return AjaxResult.success();
    }

    @ApiOperation("修改商品图片表")
    @PutMapping
    public AjaxResult modify(@RequestBody GoodsPics goodsPics) {
        goodsPicsService.modify(goodsPics);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除商品图片表")
    @DeleteMapping("/{picsId}")
    public AjaxResult removeById(@PathVariable Serializable picsId) {
        goodsPicsService.removeById(picsId);
        return AjaxResult.success();
    }

}
